cmake_minimum_required(VERSION 3.15)
project(motor_control)

set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)

file(GLOB_RECURSE SOURCE "${CMAKE_CURRENT_LIST_DIR}/src/*.c")

message(STATUS "Source files: ${SOURCE}")


set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET "AARCH64")
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_FAST_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIB_PTHREAD 1)
set (WAMR_BUILD_THREAD_MGR 1)
set (WAMR_BUILD_SHARED_MEMORY 1)

set (WAMR_ROOT_DIR /home/blkan/wasm/wasm-micro-runtime)

# 构建运行时的库
# runtime_lib.cmake会完成WAMR的配置，将运行时库相关的源文件放到变量WAMR_RUNTIME_LIB_SOURCE，以及添加库对应的头文件搜寻目录
# 将WAMR_RUNTIME_LIB_SOURCE的源文件构建成一个静态库
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(libiwasm STATIC ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)

# 包含shared_uncommon.cmake，此脚本会添加一些iwasm的main文件会使用到的工具函数，比如读取wasm模块文件的函数
# 它将相关的源文件保存至变量UNCOMMON_SHARED_SOURCE
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)

add_executable(motor_control ${UNCOMMON_SHARED_SOURCE} ${SOURCE})

target_include_directories(motor_control PRIVATE  ${CMAKE_CURRENT_LIST_DIR}/inc)

target_link_libraries(motor_control PRIVATE libiwasm -lpthread -lrt -ldl -lm)
